from forms.models import *
from django.contrib import admin

class FieldInline(admin.StackedInline):
    model = Field
    extra = 1

class CheckboxFieldValueInline(admin.TabularInline):
    model = CheckboxFieldValue
    extra = 1

class RadioFieldValueInline(admin.TabularInline):
    model = RadioFieldValue
    extra = 1
    
class FormAdmin(admin.ModelAdmin):
    raw_id_fields = ('author',)
    readonly_fields = ('ranking',)
    fieldsets = [
        (None,               {'fields': ['author', 'title', 'description', 'keywords', 'published']}),
        ('Search',           {'fields': ['ranking'], 'classes': ['collapse']}),
        ('Date information', {'fields': ['start_pub', 'end_pub', 'duration', 'duration_unit'], 'classes': ['collapse']}),
    ]
    inlines = [FieldInline]
    list_display = ('title', 'author', 'published', 'ranking')

class FieldAdmin(admin.ModelAdmin):
    raw_id_fields = ('form',)
    
class TextFieldAdmin(admin.ModelAdmin):
    raw_id_fields = ('field',)
    
class TextareaFieldAdmin(admin.ModelAdmin):
    raw_id_fields = ('field',)

class CheckboxFieldAdmin(admin.ModelAdmin):
    raw_id_fields = ('field',)
    inlines = [CheckboxFieldValueInline]

class RadioFieldAdmin(admin.ModelAdmin):
    raw_id_fields = ('field',)
    inlines = [RadioFieldValueInline]

admin.site.register(CheckboxField, CheckboxFieldAdmin)    
admin.site.register(TextField, TextFieldAdmin)
admin.site.register(Field, FieldAdmin)
admin.site.register(Form, FormAdmin)
admin.site.register(TextareaField, TextareaFieldAdmin)
admin.site.register(RadioField, RadioFieldAdmin)